use bytes::Bytes;

/// 标识一个dialog..
/// 此类作为map的key时,只判断call_id的值.而不比较id.
///	因此,此类实现了Hash,PartialEq,PartialOrd.都是根据call_id进行判断.
#[derive(Debug,  Eq, Clone)]
pub(crate) struct DialogIdent {
	id: u32,
	call_id: Bytes,
}

impl PartialEq for DialogIdent {
	fn eq(&self, other: &Self) -> bool {
		(&self.call_id) == &other.call_id
	}
}


impl Ord for DialogIdent {
		fn cmp(&self, other: &Self) -> std::cmp::Ordering {
			(&self.call_id).cmp(&other.call_id)
		}
}

impl PartialOrd for DialogIdent {
	fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
		Some(self.cmp(other))
	}
}

impl DialogIdent {
	pub(crate) fn new(id: u32, call_id: Bytes) -> Self {
		Self { id, call_id }
	}
	pub(crate) fn id(&self) -> u32 {
		self.id
	}

	// pub(crate) fn call_id(&self) -> &Bytes {
	// 	&self.call_id
	// }
}

impl From<&Bytes> for DialogIdent {
	fn from(call_id: &Bytes) -> Self {
		Self {
			id: 0,
			call_id: call_id.clone(),
		}
	}
}
